package com.yt.chapter1.thread;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by Administrator on 2019/1/24 23:28
 */
public class threadSearchBook implements Runnable {
    ArrayList<PhoneBook> array;
    String name;

    public threadSearchBook(String name, ArrayList<PhoneBook> array) {
        if(array!=null) {
            this.array = array;
        }
        this.name = name;


    }

    @Override
    public void run() {
        Iterator iterator = array.iterator();
        int num = 1;
        while (iterator.hasNext()) {
            PhoneBook phoneBook = (PhoneBook) iterator.next();
            if (phoneBook.getName().equals(name)) {
                System.out.println("姓名：" + phoneBook.getName() + "/电话：" + phoneBook.getPhone() + "/地址：" + phoneBook.getAdress());
                return;
            }
        }

    }
}
